﻿using System.Drawing;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace WebComponents.Templates.AdminControlProj
{
    [DefaultProperty("Text")]
    [ToolboxData("<{0}:PageLayout runat=server></{0}:PageLayout>")]
    public class PageLayout : Control
    {
        [
        Bindable(true),
        Category("Appearance"),
        DefaultValue(""),
        Description("Setting page layout, installs Css"),
        Localizable(true)
        ]
        /// <summary>
        /// Current layouts: 
        ///     Reset which is simple page layout
        ///     Main which is main page layout
        /// </summary>
        private string selectedLayout;
        public virtual string  SelectedLayout {
            get 
            {
                return this.selectedLayout;
            }
            set
            {
                this.selectedLayout = value;
            }
        }
        /// <summary>
        /// Order inside <head></head> tag.
        /// </summary>
        private int indexPosition = 1;
        public virtual int IndexPosition
        {
            get
            {
                return this.indexPosition;
            }
            set
            {
                this.indexPosition = value;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="e"></param>
        private ILayoutName layoutName = ILayoutName.Reset;
        public virtual ILayoutName LayoutName
        {
            get
            {
                return this.layoutName;
            }
            set
            {
                this.layoutName = value;         
            }
        }
        public enum ILayoutName
        {
            Reset = 0,
            Main = 1
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            HtmlLink link = new HtmlLink();
            link.Attributes.Add("href", this.Page.ClientScript.GetWebResourceUrl(this.GetType(), String.Format("WebComponents.Templates.AdminControlProj.Css.{0}.css", this.SelectedLayout)));
            link.Attributes.Add("type", "text/css");
            link.Attributes.Add("rel", "stylesheet");
            this.Page.Header.Controls.AddAt(this.IndexPosition, link);
            
        }
    }
}
